//
//  Extension.swift
//  weibo10
//
//  Created by 晁岳山 on 15/10/15.
//  Copyright © 2015年 晁岳山. All rights reserved.
//

import UIKit


extension UIButton {
    
    //便利构造函数
    convenience init(imageName: String, backImageName: String?) {
        self.init()
        
        setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        setImage(UIImage(named: imageName + "_highlighted"), forState: UIControlState.Highlighted)
        if let backImageName = backImageName {
            setBackgroundImage(UIImage(named: backImageName), forState: UIControlState.Normal)
            setBackgroundImage(UIImage(named: backImageName + "_highlighted"), forState: UIControlState.Highlighted)
        }
        
        sizeToFit()
    }
    //便利构造函数  创建登录 注册按钮
    convenience init(backImageName: String, btnName: String, color: UIColor = UIColor.darkGrayColor()) {
        self.init()
        setBackgroundImage(UIImage(named: backImageName), forState: UIControlState.Normal)
        setTitle(btnName, forState: UIControlState.Normal)
        setTitleColor(color, forState: UIControlState.Normal)
        sizeToFit()
    }
    //便利构造函数  创建登录 注册按钮
    convenience init(imageName: String?,
        fontSize: CGFloat,
        btnName: String,
        color: UIColor = UIColor.darkGrayColor(),
        backGroundColor: UIColor? = nil) {
            
            self.init()
            if let imageName = imageName {
                
                setImage(UIImage(named: imageName), forState: UIControlState.Normal)
            }
            setTitle(btnName, forState: UIControlState.Normal)
            setTitleColor(color, forState: UIControlState.Normal)
            titleLabel?.font = UIFont.systemFontOfSize(fontSize)
<<<<<<< HEAD
            backgroundColor = backGroundColor
=======
            backgroundColor = backgroundColor
>>>>>>> 31b3621e0c1aa1da74379c637e43582d7ba4ddfe
            sizeToFit()
    }
}
